<?php if ( ! defined('WDK_PATH')) exit('No direct script access allowed');
require_once BASE_PATH.'app/controller.php';
class Attend extends Controller
{
	private $rand_memo;
	function __construct()
	{
		parent::__construct();
		$this->_init();
	}
	
	protected function _init() 
	{
		parent::_loginCheck();
		$this->rand_memo = array(	"http://www.ppuying.com/",
									"뿌잉 닷컴",
									"오늘 하루도 즐겁게~!",
									"신나는 하루!"
									);
	}
	
	public function index()
	{
		$this->_index();
		/*****************************************************************************************************************************
		 * BASIC VARS
		*****************************************************************************************************************************/
		$assign_data = array();
		$lm = Wdk::get('UserAttendManager');
		$lists = array();
		/****************************************************************************************************************************/
		try 
		{
			$assign_data['rand_memo'] = $this->rand_memo[rand(0, count($this->rand_memo)-1)];
			$lm['listsize'] = 50;
			$lm['page'] = 1;
			$lm->load();
			foreach($lm['lists'] as $idx=>$list)
			{
				$data = array(	'seq'			=>	$list['user_attend_seq'],
								'date'			=>	$list['user_attend_date'],
								'user_login_id'	=>	$list['user_login_id'],
								'user_nick'		=>	$list['user_nick_str'],
								'memo'			=>	$list['user_attend_memo'],
								'point'			=>	$list['user_attend_point'],
								'continue'		=>	$list['user_attend_continue'],
								'insert_time'	=>	$list['user_attend_insert_time_str']
							);
				array_push($lists, $data);
			}
			$assign_data['lists'] = $lists;
		}
		catch(NoRecordException $e)
		{
			$assign_data['lists'] = array();
		}
		catch(WException $e)
		{
			parent::_error($e);
		}
		/*****************************************************************************************************************************
		 * RESULT
		*****************************************************************************************************************************/	
		parent::_view($assign_data);
		/****************************************************************************************************************************/
	}
	
	private function _index()
	{
		if(parent::_isPost() == false) return;
		/*****************************************************************************************************************************
		 * BASIC VARS
		*****************************************************************************************************************************/
		$attend = Wdk::get('UserAttend');
		/****************************************************************************************************************************/
		try 
		{
			$attend['fk_user_seq'] 		= $this->session['user_seq'];
			$attend['user_attend_memo'] = (string) post('user_attend_memo');
			$attend->insert();
		}
		catch(WException $e)
		{
			parent::_script(array("alert('출석체크는 하루 한번 가능합니다.');", "history.back();"));
		}
		/*****************************************************************************************************************************
		 * RESULT
		*****************************************************************************************************************************/	
		parent::_redirect("/user/attend");
		/****************************************************************************************************************************/
	}
}